package single;

/**
 * @author wang'ji'cheng
 * @date 2025/7/14
 * 懒汉式：只有在调用时才会实例化，不会有资源的浪费，但是有线程安全问题。
 * 实现：构造器私有化 ，定义一个静态属性对象，提供一个公共的static方法，返回对象。
 */

public class People {
   private String name;
   private static People people;
   public static int a = 999;

   private People(){

   }
   private People(String name){
       System.out.println("构造器调用了吗？");
       this.name = name;

   }


   public  static People get(){
       if (people==null){
            people = new People("李四");
       }

       return people;

   }

    @Override
    public String toString() {
        return "People{" +
                "name='" + name + '\'' +
                '}';
    }
}
